<?php 
require_once("../includes/config.php"); 
  //dump($_GET);
  //if the request comes through GET Request
  if ($_SERVER["REQUEST_METHOD"] == "GET"&&$_SESSION['r']<=1) {
 if($_GET['disable'] == 20)
    {
      //Check if has contracts related
     // $query = query('SELECT * FROM contracts WHERE apartment_id =?',$_GET['id']);
	  $result= query('SELECT * FROM apartments WHERE id=?',$_GET['id']);
      if( $result[0]['status']== 2 || $result[0]['status']== 3 || $result[0]['status']== 4 )
      {
	  $sql= query("SELECT * FROM apart_status WHERE status_id = ?",7);
	 
       $update= query("UPDATE apartments SET status= ? WHERE id=?",$sql[0]['status_id'],$_GET['id']);
        $_SESSION['success_message'] = "تم غلق الوحدة بنجاح"; 
		  redirect("apartments.php?page='". $_GET["pages"]."'");    
      }
      
	  else {
	  $_SESSION['error_message'] = "لايمكن غلق هذه الوحده حاليا";
	  }
      redirect("apartments.php?page='". $_GET["pages"]."'");    
    }
  
}else {
apologize("Sorry!");
}  
  
  ?>